/******************************************************************************
 *
 * MotionViewer
 * Copyright (C) 2007 Sangyoon Lee, Electronic Visualization Laboratory, 
 * University of Illinois at Chicago
 *
 * This software is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either Version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser Public License along
 * with this software; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Questions or comments about MotionViewer should be directed to 
 * cavern@evl.uic.edu
 *
 *****************************************************************************/

// v file loader original code from http://mocap.cs.cmu.edu/tools.php

#ifndef __VICONVFILEDATA_H__
#define __VICONVFILEDATA_H__

#include <vector>
#include <fstream>
#include <iostream>
#include <string>

#include "ViconMotionDataSet.h"
#include <ogreplatform.h>
class ViconVFileData: public ViconMotionDataSet
{
public:
	ViconVFileData();
	virtual ~ViconVFileData();

	virtual void	rewind();
	virtual void	update(float addedTime);
	virtual void	connectToSource(const char* source) { loadFile(source);}
	virtual void	getMarkerPosition(int id, float* pos);
	virtual void	getBodyTranslation(int id, float* trans, bool global = true);
	virtual void	getBodyRotation(int id, float* rot, bool global = true);
	virtual void	getBodyQuaternion(int id, float* qt, bool global = true);

	bool			loadFile(const char* filename);
	
protected:
	
	virtual void	updateDebug();	
	
	bool readHeader(std::ifstream &v);
	void readSections(std::ifstream &v);
	void readDataGroup(std::ifstream &v, int len);
	void readMarkerChannels(std::ifstream &v);
	void readBodyChannels(std::ifstream &v, bool global = true);
	void readDynamics(std::ifstream &v);
	void reconstructDataSet();

	float			m_fCurrTime;

	int m_iMarkerGroupID;
	int m_iLocalBodyGroupID;
	int m_iGlobalBodyGroupID;
	int m_iNumMarkerChannels;
	int m_iNumGBodyChannels;
	int m_iNumLBodyChannels;

	// frame data: temporarily raw data storage
	std::vector< std::vector<double> > gbody_frames;
	std::vector< std::vector<double> > lbody_frames;
	std::vector< std::vector<double> > marker_frames;
	
	// processed frame dataset: [frames][channel]
	std::vector< std::vector<MarkerData> >	m_vMarkerData;
	std::vector< std::vector<BodyData> >		m_vBodyData;

	
};

#endif